-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type for join method #4421
base: 3.x
Are you sure you want to change the base?
Add type for join method #4421
Conversation
src/Extension/CoreExtension.php
Outdated
* @param array $value An array | ||
* @param string $glue The separator | ||
* @param string|null $and The separator for the last pair | ||
* @param iterable|array|string|float|int|bool|object|null $value An array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object
should probably be Stringable
instead, as non-stringable objects won't work in implode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is casted to array, https://3v4l.org/FqgLS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. This is probably unexpected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what to do?
/cc @fabpot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest not including object
in the type here (without changing the implementation for now). This would make TwigStan report cases triggering this weird behavior as mistakes.
I'm not sure about the scalar types, for which the casting is more usable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done!
Looking at the code, this method is very forgiving in what it accepts.
@fabpot this one is ready |
You can see here how it works: I had to ignore the error that is fixed by this PR: |
@fabpot What's needed to get this PR merged? Do I need to do changes? |
Looking at the code, this method is very forgiving in what it accepts.
This helps PHPStan to not complain when something other than an array is passed.
Did I miss other types?
/cc @stof